Repository navigation
fix: robust 404 handling for all unmatched paths - #90
Merged
Merged
Conversation
The notFound handler now returns 404 for all unmatched paths instead of rendering the index page as a 200 SPA fallback. Three layers of defense: 1. Dot-prefixed segments (/.well-known/, /.git/, /.env) → 404 early exit 2. File extension in last segment (wp-login.php, robots.txt) → 404 3. All remaining paths: try rendering index with 404 status; if the render throws (e.g. index expects loader props), catch and serve the error page as 404 Previously, paths like /wp-admin, /foo/bar/baz, and /.well-known/traffic-advice either returned 500 (index crash) or 200 (SPA fallback). Now they all return 404. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cpojer
pushed a commit
that referenced
this pull request
Sep 11, 2026
Asset-heavy deploys (e.g. 87 MiB / 199 files) saw "Connection Lost"
because `parseMultipart` + sequential KV/R2 puts ran in the handler
body before `new Response(stream)`, blocking 30-60s with zero
response bytes. CF edge / intermediaries closed the socket before
the NDJSON stream ever started.
Restructure the handler: build the TransformStream + writer +
heartbeat first, wrap parse + validate + full pipeline in a
fire-and-forget IIFE that writes to the stream, and return the
Response in milliseconds so headers flush immediately. In-parse
error branches that used to return 4xx JSON now emit NDJSON
`{event:'error'}` through the shared writer; pre-stream guards
(401/403/404/409/invalid content-type) still return 4xx. Dedupe
short-circuit now emits through the same writer instead of building
its own Response.
Plumb `DEPLOY_HEARTBEAT_INTERVAL_MS` (default 15000) so tests can
exercise the heartbeat path without waiting real seconds. Migrate
25 test assertions from `toBe(400|413|429)` to NDJSON error-event
checks, and add two regression tests: incremental stream consumption
proves `start` is the first non-heartbeat event, and a sub-second
heartbeat interval proves heartbeats fire across the full pipeline.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The notFound handler now returns 404 for all unmatched paths instead of
rendering the index page as a 200 SPA fallback. Three layers of defense:
render throws (e.g. index expects loader props), catch and serve
the error page as 404
Previously, paths like /wp-admin, /foo/bar/baz, and
/.well-known/traffic-advice either returned 500 (index crash) or 200
(SPA fallback). Now they all return 404.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Note
Medium Risk
Changes the pages-mode
app.notFoundbehavior from a 200 SPA fallback to always returning 404 for unknown routes, which can affect SEO/caching and any clients relying on the previous 200 response. Logic is localized to routing plus expanded tests, reducing regression risk elsewhere.Overview
Makes pages-mode unmatched routes return real 404s instead of a 200 SPA index fallback.
The
app.notFoundhandler now (1) blocks any/.path segment (e.g./.well-known,/.git,/.env), (2) blocks last-segment dotted paths (e.g.robots.txt,wp-login.php), and (3) for remaining unknown paths attempts to renderindexbut wraps it in atry/catchand forces status 404 (falling back to404.html/default error page if rendering throws).Adds integration + unit coverage for common bot-probe/unknown paths, API-prefix behavior, and non-GET methods to ensure consistent 404 responses.
Reviewed by Cursor Bugbot for commit b745ff3. Bugbot is set up for automated code reviews on this repo. Configure here.